$OpenBSD: patch-yuvdenoise_main_c,v 1.1 2017/05/24 09:26:35 espie Exp $

Index: yuvdenoise/main.c
--- yuvdenoise/main.c.orig
+++ yuvdenoise/main.c
@@ -312,7 +312,7 @@ temporal_filter_planes_MC (int idx, int w, int h, int 
 		v /= 16;
 
 		// add weighted and translated but non-filtered test-pixel
-		d = t - abs (r-v);
+		d = t - (r > v ? r-v : v-r);
 		d = d<0? 0:d;
 	  	c += d;
           	m += *(f1+(x+sx+x1)+(y+sy+y1)*w)*d;
@@ -356,7 +356,7 @@ temporal_filter_planes_MC (int idx, int w, int h, int 
 		v /= 16;
 
 		// add weighted and translated but non-filtered test-pixel
-		d = t - abs (r-v);
+		d = t - (r > v ? r-v : v-r);
 		d = d<0? 0:d;
 	  	c += d;
           	m += *(f3+(x+sx+x3)+(y+sy+y3)*w)*d;
@@ -378,7 +378,7 @@ temporal_filter_planes_MC (int idx, int w, int h, int 
 		v /= 16;
 
 		// add weighted and translated but non-filtered test-pixel
-		d = t - abs (r-v);
+		d = t - (r > v ? r-v : v-r);
 		d = d<0? 0:d;
 	  	c += d;
           	m += *(f5+(x+sx+x5)+(y+sy+y5)*w)*d;
@@ -400,7 +400,7 @@ temporal_filter_planes_MC (int idx, int w, int h, int 
 		v /= 16;
 
 		// add weighted and translated but non-filtered test-pixel
-		d = t - abs (r-v);
+		d = t - (r > v ? r-v : v-r);
 		d = d<0? 0:d;
 	  	c += d;
           	m += *(f6+(x+sx+x6)+(y+sy+y6)*w)*d;
@@ -422,7 +422,7 @@ temporal_filter_planes_MC (int idx, int w, int h, int 
 		v /= 16;
 
 		// add weighted and translated but non-filtered test-pixel
-		d = t - abs (r-v);
+		d = t - (r > v ? r-v : v-r);
 		d = d<0? 0:d;
 	  	c += d;
           	m += *(f7+(x+sx+x7)+(y+sy+y7)*w)*d;
@@ -708,7 +708,7 @@ void temporal_filter_planes_p (int idx, int w, int h, 
 		d += *(f3+1+w);
 		d /= 16;
 
-		d = t - abs (r-d);
+		d = t - (r > d ? r-d : d-r);
 		d = d<0? 0:d;
 		c += d;
 		m += *(f3)*d*2;
@@ -740,7 +740,7 @@ void temporal_filter_planes_p (int idx, int w, int h, 
 		d += *(f1+1+w);
 		d /= 16;
 
-		d = t - abs (r-d);
+		d = t - (r > d ? r-d : d-r);
 		d = d<0? 0:d;
 		c += d;
 		m += *(f1)*d*2;
@@ -756,7 +756,7 @@ void temporal_filter_planes_p (int idx, int w, int h, 
 		d += *(f5+1+w);
 		d /= 16;
 
-		d = t - abs (r-d);
+		d = t - (r > d ? r-d : d-r);
 		d = d<0? 0:d;
 		c += d;
 		m += *(f5)*d*2;
@@ -772,7 +772,7 @@ void temporal_filter_planes_p (int idx, int w, int h, 
 		d += *(f6+1+w);
 		d /= 16;
 
-		d = t - abs (r-d);
+		d = t - (r > d ? r-d : d-r);
 		d = d<0? 0:d;
 		c += d;
 		m += *(f6)*d*2;
@@ -788,7 +788,7 @@ void temporal_filter_planes_p (int idx, int w, int h, 
 		d += *(f7+1+w);
 		d /= 16;
 
-		d = t - abs (r-d);
+		d = t - (r > d ? r-d : d-r);
 		d = d<0? 0:d;
 		c += d;
 		m += *(f7)*d*2;
